import { defineStore } from 'pinia'
import { getApiStatic } from '@/api'
import type { RootObject, Children, ChinaTotal, ChinaAdd, StatisGradeCityDetail } from './type'

export const useStore = defineStore({
    id: 'list',
    state: () => ({
        list: <RootObject>{},
        item: <Children[]>[],
        ChinaAdd: <ChinaAdd>{},
        ChinaTotal: <ChinaTotal>{},
        cityDetail: <StatisGradeCityDetail[]>[],
    }),
    getters: {
    },
    actions: {
        async getList() {
            const res = await getApiStatic()
            this.list = res
            this.ChinaAdd = this.list.chinaAdd
            this.ChinaTotal = this.list.chinaTotal
            this.cityDetail = this.list.statisGradeCityDetail.sort((a, b) => b.nowConfirm - a.nowConfirm).slice(0, 10)
        },
    }
})
